package com.kaisheng.service;

import java.util.List;

import com.kaisheng.dao.ContactDao;
import com.kaisheng.dao.ContactUserDao;
import com.kaisheng.entity.Contact;
import com.kaisheng.entity.ContactUser;
import com.kaisheng.util.DateUtil;
import com.kaisheng.util.PKUtil;

public class ContactService {

	ContactDao contactDao = new ContactDao();
	ContactUserDao c_udao = new ContactUserDao();
	public void save(String name, String company, String cellphone,String phone,String email,
			String address, String homepage, String weibo,String textarea,String project_id) 
	{
		Contact c = new Contact();
		c.setId(PKUtil.getId());
		c.setName(name);
		c.setCompany(company);
		c.setCellphone(cellphone);
		c.setPhone(phone);
		c.setEmail(email);
		c.setAddress(address);
		c.setHomepage(homepage);
		c.setWeibo(weibo);
		c.setIntroduction(textarea);
		c.setCreatetime(DateUtil.getNowDateTime());
	
		c.setProject_id(project_id);
		
		contactDao.save(c);
		
		
	}

	public void update(String id,String name, String company, String cellphone,String phone, String email,
			String address, String homepage,String weibo, String textarea,String project_id) {
	
		Contact c = new Contact();
		c.setId(id);
		c.setName(name);
		c.setCompany(company);
		c.setCellphone(cellphone);
		c.setPhone(phone);
		c.setEmail(email);
		c.setAddress(address);
		c.setHomepage(homepage);
		c.setWeibo(weibo);
		c.setIntroduction(textarea);
		c.setCreatetime(DateUtil.getNowDateTime());
		c.setProject_id(project_id);
		
		contactDao.updateContact(c);
		
	}

	
	public List<Contact> findAllContactsByProjectId(String project_id) {
		return contactDao.findAllByProject_id(project_id);
	
	}

	public Contact findSpecificContact(String id) {
		return  contactDao.findContactById(id);

	}

	public List<ContactUser> findAllNotes(String contactid) {
	
		return c_udao.findAllNotesById(contactid);
	}

	public void save(String contactid, String userid, String event) {
		ContactUser cu = new ContactUser();
		cu.setId(PKUtil.getId());
		cu.setEvent(event);
		cu.setCreatetime(DateUtil.getNowDateTime());
		cu.setContact_id(contactid);
		cu.setUser_id(userid);
		c_udao.saveNote(cu);
		
	}

	public void deleteContact(String id) {
		contactDao.deleteContactById(id);
		
	}

	public void deleteNote(String noteid) {
		c_udao.deleteNoteById(noteid);
		
	}

	public ContactUser findContactUser(String cuid) {
		
		return c_udao.findById(cuid);
	}

	public void update(String editcontent, String cuid) {
		c_udao.update(editcontent,cuid);
	}



	
	
}
